﻿@functions {
	private List<SelectListItem> TriStateValues
	{
		get
		{
			return new List<SelectListItem>
					   {
						   new SelectListItem
							   {
								   Selected = !ModelValue.HasValue,
								   Text = "Not Set",
								   Value = string.Empty
							   },
						   new SelectListItem
							   {
								   Selected = ModelValue.HasValue && ModelValue.Value,
								   Text = "True",
								   Value = "true"
							   },
						   new SelectListItem
							   {
								   Selected = ModelValue.HasValue && !ModelValue.Value,
								   Text = "False",
								   Value = "false"
							   },
					   };
		}
	}

	private bool? ModelValue
	{
		get
		{
			if (ViewData.Model == null)
			{
				return null;
			}

			return Convert.ToBoolean(ViewData.Model, CultureInfo.InvariantCulture);
		}
	}
}

@if (ViewData.ModelMetadata.IsNullableValueType)
{
	@Html.DropDownList(string.Empty, TriStateValues)
}
else
{
	@Html.CheckBox(string.Empty, ModelValue ?? false)
}